package com.mindmap.ui;

import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

public class ToolBarPanel extends JPanel {
    private MainFrame mainFrame;

    public ToolBarPanel(MainFrame mainFrame) {
        this.mainFrame = mainFrame;
        setLayout(new FlowLayout(FlowLayout.LEFT));
        initButtons();
    }

    private void initButtons() {
        addButton("新建", e -> mainFrame.newMindMap());
        addButton("打开", e -> mainFrame.openMindMap());
        addButton("保存", e -> mainFrame.saveMindMap());
        addButton("导出", e -> mainFrame.exportToImage());

        add(Box.createHorizontalStrut(20));

        addButton("添加子节点", e -> mainFrame.addChildNode());
        addButton("添加兄弟节点", e -> mainFrame.addSiblingNode());
        addButton("删除节点", e -> mainFrame.deleteNode());

        add(Box.createHorizontalStrut(20));

        addButton("自动布局", e -> mainFrame.setAutoLayout());
        addButton("左侧布局", e -> mainFrame.setLeftLayout());
        addButton("右侧布局", e -> mainFrame.setRightLayout());
    }

    private void addButton(String text, ActionListener listener) {
        JButton button = new JButton(text);
        button.addActionListener(listener);
        add(button);
    }
}
